/*
 *
 * Version 1.00
 * 
 * Created on 2007-6-4
 * Encoding UTF-8
 */
package net.comm.message.web.action;

import java.util.List;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import net.comm.common.GlbFinal;
import net.comm.common.ReturnMessage;


import net.comm.message.bean.BaseMessage;
import net.comm.message.service.impl.MessageServiceImpl;
import net.comm.message.web.form.MessageForm;
import net.comm.message.web.form.MsgcontForm;
import net.comm.page.PageCtr;
import net.comm.util.HtmlMessageBox;
import net.comm.util.StringUtil;
import net.comm.web.base.AbstractBaseAction;


/**
 *站内邮件Action
 * @author hcgong(hcgong@sina.com)
 * @version 1.0
 * @date 2007-6-4
 */
public class MessageAction extends AbstractBaseAction {
	
	private MessageServiceImpl service = null;
	
	/**
	 * struct-config中该ACTION中的每个forward的常量定义
	 */
	final String LIST_FORWARD = "list";
	final String OPER_FORWARD = "oper";
	final String SEND_FORWARD = "send";
	final String LOGIN_FORWARD = "loginFwd";
	
	
	/**
	 *构造方法
	 */
	public MessageAction()
	{
		super(false);
		
		/**
		 * 初始化业务组件接口
		 */
		service = new MessageServiceImpl();
	}
	
	/**
	 * 默认动作
	 * 1.action值为空的时候,进入查询页面
	 * 2.每个操作都执行的代码,但是方法必须返回null
	 * @param mapping	 跳转的mapping值	
	 * @param request	 HttpServletRequest对象
	 * @param response	 HttpServletResponse对象
	 */
	public ActionForward startAction(ActionMapping mapping, ActionForm form,
									 HttpServletRequest request , 
									 HttpServletResponse response)
	{
		String action = getReqParam(request , ACTION_KEY);
		if(action == null || action.trim().length() == 0) {
			return mapping.findForward(LIST_FORWARD);
		} else {
			return null;
		}
	}
	
	/**
	 * 查询站内邮件清单
	 * @param mapping		跳转的mapping值		
	 * @param request		HttpServletRequest对象
	 * @param response		HttpServletResponse对象
	 * @return
	 * @throws Exception
	 */
	public ActionForward list(ActionMapping mapping, ActionForm form,
							  HttpServletRequest request , 
							  HttpServletResponse response) 
		throws Exception
	{
		MessageForm theForm = (MessageForm)form;
		
		Integer userID = (Integer)request.getSession().getAttribute(GlbFinal.SESSION_USERID);
		if(userID == null || userID == 0 ){
			
			return mapping.findForward(LOGIN_FORWARD);
		}		
		if(theForm.getQryReceiver() == 0 && theForm.getQrySender() == 0 
				&& theForm.getQrySendertype().equals("")){
			return mapping.findForward(LOGIN_FORWARD);
		}
		
		// 生成分页对象	
		theForm.setPage(this.getPageFromReq(request,15));
		
		ReturnMessage msg  = new ReturnMessage();

		/**
		 *调用services中的方法
		 */
		List list = null;
		//查询私聊信息
		String queryType = request.getParameter("queryType");
		request.setAttribute("queryType", queryType);
		if("privateMsg".equals(queryType)) {
			list = service.listPrivateMsg(theForm, msg);
		} else {
			list = service.list(theForm , msg);
		}
		
		if(msg.getErrCode() != GlbFinal.ERRCODE_SUCCESS) 
		{
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_CALLALERTMETHOD);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);
		}
		
		/**
		 *设置列表的数据
		 */
		setAction(request, "list");
		request.setAttribute("msglist" , list);
		request.setAttribute("theForm", theForm);
		
		/**
		 * 设置分页对象,key,lastkey到request中
		 * 使用分页组件,必须设置这三个值
		 */
		request.setAttribute(PAGE_KEY , theForm.getPage());
		request.setAttribute(KEY , theForm.getKey());
		request.setAttribute(LAST_KEY , theForm.getLastKey());
		
		/**
		 * 转发到LIST_FORWARD指定的jsp文件
		 */
		return mapping.findForward(LIST_FORWARD);
	}
	
	/**
	 * 查询站内邮件清单
	 * @param mapping		跳转的mapping值		
	 * @param request		HttpServletRequest对象
	 * @param response		HttpServletResponse对象
	 * @return
	 * @throws Exception
	 */
	public ActionForward adlist(ActionMapping mapping, ActionForm form,
							  HttpServletRequest request , 
							  HttpServletResponse response) 
		throws Exception
	{
		MessageForm theForm = (MessageForm)form;
		
		Integer userID = (Integer)request.getSession().getAttribute(GlbFinal.SESSION_USERID);
		if(userID == null || userID == 0 ){
			
			return mapping.findForward(LOGIN_FORWARD);
		}		
		if(theForm.getQryReceiver() == 0 && theForm.getQrySender() == 0 
				&& theForm.getQrySendertype().equals("")){
			return mapping.findForward(LOGIN_FORWARD);
		}
		
		// 生成分页对象	
		theForm.setPage(this.getPageFromReq(request,15));
		
		ReturnMessage msg  = new ReturnMessage();

		/**
		 *调用services中的方法
		 */
		List list = service.adlist(theForm , msg);
		if(msg.getErrCode() != GlbFinal.ERRCODE_SUCCESS) 
		{
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_CALLALERTMETHOD);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);
		}
		
		/**
		 *设置列表的数据
		 */
		setAction(request, "adlist");
		request.setAttribute("msglist" , list);
		request.setAttribute("theForm", theForm);
		
		/**
		 * 设置分页对象,key,lastkey到request中
		 * 使用分页组件,必须设置这三个值
		 */
		request.setAttribute(PAGE_KEY , theForm.getPage());
		request.setAttribute(KEY , theForm.getKey());
		request.setAttribute(LAST_KEY , theForm.getLastKey());
		
		/**
		 * 转发到LIST_FORWARD指定的jsp文件
		 */
		return mapping.findForward(LIST_FORWARD);
	}	
	/**
	 * 查询站内邮件内容
	 * @param mapping		跳转的mapping值		
	 * @param request		HttpServletRequest对象
	 * @param response		HttpServletResponse对象
	 * @return
	 * @throws Exception
	 */
	public ActionForward detail(ActionMapping mapping, ActionForm form,
							  HttpServletRequest request , 
							  HttpServletResponse response) 
		throws Exception
	{
		MessageForm theForm = (MessageForm)form;
		
		Integer userID = (Integer)request.getSession().getAttribute(GlbFinal.SESSION_USERID);
		if(userID == null || userID == 0 ){
			
			return mapping.findForward(LOGIN_FORWARD);
		}		
		if(theForm.getQryReceiver() == 0 && theForm.getQrySender() == 0 
				&& theForm.getQrySendertype().equals("")){
			return mapping.findForward(LOGIN_FORWARD);
		}
		
		// 生成分页对象	
		theForm.setPage(this.getPageFromReq(request,3));
		
		ReturnMessage msg  = new ReturnMessage();

		/**
		 *调用services中的方法
		 */
		List list = service.detail(theForm, msg);
		if(msg.getErrCode() != GlbFinal.ERRCODE_SUCCESS) 
		{
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_CALLALERTMETHOD);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);
		}
		
		/**
		 *设置列表的数据
		 */
		setAction(request, "list");
		request.setAttribute("msglist" , list);
		request.setAttribute("theForm", theForm);
		
		/**
		 * 设置分页对象,key,lastkey到request中
		 * 使用分页组件,必须设置这三个值
		 */
		request.setAttribute(PAGE_KEY , theForm.getPage());
		request.setAttribute(KEY , 		theForm.getKey());
		request.setAttribute(LAST_KEY , theForm.getLastKey());
		
		/**
		 * 转发到LIST_FORWARD指定的jsp文件
		 */
		return mapping.findForward(OPER_FORWARD);
	}
	/**
	 * 处理站内邮件，状态改为已读，如果是好友请求，则转好友请求页面；
	 * 如果是验证，则转验证通过页面
	 * @param mapping		跳转的mapping值		
	 * @param request		HttpServletRequest对象
	 * @param response		HttpServletResponse对象
	 * @return
	 * @throws Exception
	 */
	public ActionForward deal(ActionMapping mapping, ActionForm form,
							  HttpServletRequest request , 
							  HttpServletResponse response) 
		throws Exception
	{
		MessageForm theForm = (MessageForm)form;
		
		Integer userID = (Integer)request.getSession().getAttribute(GlbFinal.SESSION_USERID);
		if(userID == null || userID == 0 ){
			
			return mapping.findForward(LOGIN_FORWARD);
		}		
		ReturnMessage msg  = new ReturnMessage();

		/**
		 *调用services中的方法
		 */
		service.deal(theForm, msg);
		if(msg.getErrCode() != GlbFinal.ERRCODE_SUCCESS) 
		{
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_CALLALERTMETHOD);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);
		}
		String nexturl = GlbFinal.FOLDER_INSTALL + "/msg.do?action=list&qryReceiver="+ theForm.getReceiver();
		msg.setMsg("处理成功！");
		HtmlMessageBox hmb = new HtmlMessageBox();
		hmb.setAlertType(HtmlMessageBox.ALERTTYPE_PRINTTOHTML);
		hmb.setPrintMessage(msg.getMsg());
		hmb.setForwardUrl(nexturl);
		return showMsg(hmb , request , response , mapping);			
		
	}
		
	/**
	 *获得站内邮件
	 */
	public ActionForward get(ActionMapping mapping, ActionForm form,
							 HttpServletRequest request , 
							 HttpServletResponse response)
		throws Exception
	{

		MessageForm theForm = (MessageForm)form;
		
		String userID = (String)request.getSession().getAttribute(GlbFinal.SESSION_USERID);
		if(userID == null || userID.equals("")){
			
			return mapping.findForward(LOGIN_FORWARD);
		}		
		String strPos = getReqParam(request, "pos");
		
		int select = theForm.getSelect();
		
		int pos = Integer.parseInt(strPos);
		
		pos = pos + select - 1 - 1;//取选中的前一条记录为开始记录
		
		if(pos < 1){
			pos = 1;
		}
		
		PageCtr page  = this.getPageFromReq(request, 3);
		page.setPos(pos);
		theForm.setPage(page);
		
		ReturnMessage msg  = new ReturnMessage();
		/**
		 *赋值查询条件
		 */
		MsgcontForm msgcontForm = new MsgcontForm();
		
		/**
		 * 设置当前页面key和上页lastKey
		 */
		theForm.setLastKey(getReqParam(request, KEY));
		/**
		 *调用services中的方法
		 */
		List list = service.get(theForm, msgcontForm, msg);
		if(list.size() ==0){
			
			return list(mapping , form, request , response);
			
		}else if(msg.getErrCode() != GlbFinal.ERRCODE_SUCCESS) 
		{
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_CALLALERTMETHOD);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);
		}
		/**
		 *设置列表的数据
		 */
		setAction(request, "list");
		request.setAttribute("msglist" , list);
		request.setAttribute("theForm", theForm);
		request.setAttribute("msgcontForm", msgcontForm);
		
		/**
		 * 设置分页对象,key,lastkey到request中
		 * 使用分页组件,必须设置这三个值
		 */
		request.setAttribute(PAGE_KEY , theForm.getPage());
		request.setAttribute(KEY , theForm.getKey());
		request.setAttribute(LAST_KEY , theForm.getLastKey());
		
		/**
		 * 转发到LIST_FORWARD指定的jsp文件
		 */
		return mapping.findForward(OPER_FORWARD);
	}		
	/**
	 * 跳转到添加页面
	 */
	public ActionForward modifyPage(ActionMapping mapping, ActionForm form,
			 				 	 HttpServletRequest request , 
			 				 	 HttpServletResponse response)  
		throws Exception
	{
	
		return get(mapping , form, request , response);
	}

	/**
	 * 跳转到添加页面
	 */
	public ActionForward addPage(ActionMapping mapping, ActionForm form,
			 				 	 HttpServletRequest request , 
			 				 	 HttpServletResponse response)  
		throws Exception
	{
		MessageForm theForm = (MessageForm) form;

		request.setAttribute("theForm", theForm);
	
		return mapping.findForward(LIST_FORWARD);
	}


	/**
	 *发送站内邮件
	 */
	public ActionForward send(ActionMapping mapping, ActionForm form,
							 HttpServletRequest request , 
							 HttpServletResponse response)
		throws Exception
	{
		MessageForm theForm = (MessageForm) form;
		ReturnMessage msg  = new ReturnMessage();
		if(theForm.getReceiver() == 0) 
		{
			msg.setMsg("接收者不允许为空！");
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_PRINTTOHTML);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);			
		}
		if(theForm.getSender() == 0){
			msg.setMsg("发送者不允许为空！");
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_PRINTTOHTML);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);
		}	
		
		String lajimsg = StringUtil.getValue((String)request.getSession().getAttribute(GlbFinal.LAJIMSG));
		if(lajimsg.equals("") || !lajimsg.trim().equals(theForm.getMsg().trim())){
			
			request.getSession().setAttribute(GlbFinal.LAJIMSG, theForm.getMsg());
		}else if(lajimsg.trim().equals(theForm.getMsg().trim())){
			
			msg.setMsg("请不要发送重复信息！");
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_PRINTTOHTML);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);
		}
		
//		String msgcont = getReqParam(request, "msg");
		
		MsgcontForm msgcontForm = new MsgcontForm();
		msgcontForm.setMsg(theForm.getMsg());
		
		service.add(theForm,msgcontForm, msg);
		if(msg.getErrCode() != GlbFinal.ERRCODE_SUCCESS) 
		{
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_PRINTTOHTML);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);
		}
		if(theForm.getMtype().equals(GlbFinal.MTYPE_JIESHOU)){
			msg.setMsg("处理成功！");
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_PRINTTOHTML);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);
		}else{
			
			theForm.setQryReceiver(theForm.getReceiver());
			return list(mapping,form,request,response);
		}
	}
	/**
	 *从预览页面发送站内邮件
	 */
	public ActionForward homesend(ActionMapping mapping, ActionForm form,
							 HttpServletRequest request , 
							 HttpServletResponse response)
		throws Exception
	{
		MessageForm theForm = (MessageForm) form;
		ReturnMessage msg  = new ReturnMessage();
		if(theForm.getReceiver() == 0) 
		{
			msg.setMsg("接收者不允许为空！");
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_PRINTTOHTML);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);			
		}
		if(theForm.getSender() == 0){
			msg.setMsg("发送者不允许为空！");
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_PRINTTOHTML);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);
		}	
		
		String lajimsg = StringUtil.getValue((String)request.getSession().getAttribute(GlbFinal.LAJIMSG));
		if(lajimsg.equals("") || !lajimsg.trim().equals(theForm.getMsg().trim())){
			
			request.getSession().setAttribute(GlbFinal.LAJIMSG, theForm.getMsg());
		}else if(lajimsg.trim().equals(theForm.getMsg().trim())){
			
			msg.setMsg("请不要发送重复信息！");
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_PRINTTOHTML);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);
		}
		
//		String msgcont = getReqParam(request, "msg");
		
		MsgcontForm msgcontForm = new MsgcontForm();
		msgcontForm.setMsg(theForm.getMsg());
		
		service.add(theForm,msgcontForm, msg);
		if(msg.getErrCode() != GlbFinal.ERRCODE_SUCCESS) 
		{
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_PRINTTOHTML);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);
		}else{
			msg.setMsg("发送成功！");
			
			
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_PRINTTOHTML);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl(GlbFinal.FOLDER_INSTALL + "/users.do?action=home&userID="+ theForm.getReceiver());
			return showMsg(hmb , request , response , mapping);
			
		}
	}
	/**
	 *从预览页面发送站内邮件
	 */
	public ActionForward mainsend(ActionMapping mapping, ActionForm form,
							 HttpServletRequest request , 
							 HttpServletResponse response)
		throws Exception
	{
		MessageForm theForm = (MessageForm) form;
		ReturnMessage msg  = new ReturnMessage();
		if(theForm.getReceiver() == 0) 
		{
			msg.setMsg("接收者不允许为空！");
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_PRINTTOHTML);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);			
		}
		if(theForm.getSender() == 0){
			msg.setMsg("发送者不允许为空！");
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_PRINTTOHTML);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);
		}	
		
		String lajimsg = StringUtil.getValue((String)request.getSession().getAttribute(GlbFinal.LAJIMSG));
		if(lajimsg.equals("") || !lajimsg.trim().equals(theForm.getMsg().trim())){
			
			request.getSession().setAttribute(GlbFinal.LAJIMSG, theForm.getMsg());
		}else if(lajimsg.trim().equals(theForm.getMsg().trim())){
			
			msg.setMsg("请不要发送重复信息！");
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_PRINTTOHTML);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);
		}
		
//		String msgcont = getReqParam(request, "msg");
		
		MsgcontForm msgcontForm = new MsgcontForm();
		msgcontForm.setMsg(theForm.getMsg());
		
		service.add(theForm,msgcontForm, msg);
		if(msg.getErrCode() != GlbFinal.ERRCODE_SUCCESS) 
		{
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_PRINTTOHTML);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);
		}else{
			msg.setMsg("发送成功！");
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_PRINTTOHTML);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl(GlbFinal.FOLDER_INSTALL + "/users.do?action=main");
			return showMsg(hmb , request , response , mapping);
			
		}
	}	
	/**
	 *删除站内邮件
	 */
	public ActionForward del(ActionMapping mapping, ActionForm form,
							 HttpServletRequest request , 
							 HttpServletResponse response)
		throws Exception
	{
		MessageForm theForm = (MessageForm) form;
		
		ReturnMessage msg  = new ReturnMessage();
	
		String[] ids = request.getParameterValues("seqID");
		
		service.delete(theForm, ids, msg);
		if(msg.getErrCode() != GlbFinal.ERRCODE_SUCCESS) 
		{
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_CALLALERTMETHOD);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);
		}
		
		return list(mapping , form , request , response);
		
	}
	/**
	 *操作页面删除站内邮件
	 */
	public ActionForward operdel(ActionMapping mapping, ActionForm form,
							 HttpServletRequest request , 
							 HttpServletResponse response)
		throws Exception
	{
		MessageForm theForm = (MessageForm) form;
		
		ReturnMessage msg  = new ReturnMessage();
	
		String[] ids = request.getParameterValues("delID");
		
		service.delete(theForm, ids, msg);
		if(msg.getErrCode() != GlbFinal.ERRCODE_SUCCESS) 
		{
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_CALLALERTMETHOD);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			return showMsg(hmb , request , response , mapping);
		}
		
		request.setAttribute("theForm", theForm);

		return get(mapping , form, request , response);
	}
	
	/**
	 * 私聊,无刷新
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward sendMsg(ActionMapping mapping, ActionForm form,
							 HttpServletRequest request , 
							 HttpServletResponse response)
		throws Exception
	{
		String sender = request.getParameter("sender");
		if(sender == null || "".equals(sender)) {
			sender = request.getSession().getAttribute(GlbFinal.SESSION_USERID).toString();
		}
		String userName = request.getSession().getAttribute(GlbFinal.SESSION_NAME).toString();
		String receiver = request.getParameter("receiver");
		String msg_ = request.getParameter("msg");
		
		MessageForm theForm = new MessageForm();
		theForm.setReceiver(Integer.parseInt(receiver));
		theForm.setSender(Integer.parseInt(sender));
		theForm.setMsg(msg_);
		theForm.setMtype("1");
		theForm.setSendertype("1");
		theForm.setTitle(userName + "给你的私信");

		
		MsgcontForm msgcontForm = new MsgcontForm();
		msgcontForm.setMsg(theForm.getMsg());
		
		ReturnMessage msg  = new ReturnMessage();
		service.add(theForm,msgcontForm, msg);
		if(msg.getErrCode() != GlbFinal.ERRCODE_SUCCESS) 
		{
			HtmlMessageBox hmb = new HtmlMessageBox();
			hmb.setAlertType(HtmlMessageBox.ALERTTYPE_PRINTTOHTML);
			hmb.setPrintMessage(msg.getMsg());
			hmb.setForwardUrl("javascript:history.go(-1)");
			response.getWriter().write("0");
		}else{
			response.getWriter().write("1");
			
		}
		return null;
	}
	
	public ActionForward getMsgNum(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		String userId = request.getSession().getAttribute(GlbFinal.SESSION_USERID)
					.toString();

		int msgNum = service.getMsgNum(userId);
		
		response.setContentType("text/xml; charset='GBK'"); 
		ServletOutputStream out= response.getOutputStream();
		out.write(msgNum);
		out.flush();
		out.close(); 

		return null;
	}
}
